package com.sgb.kjwl.viewmodel.machine;

import com.sgb.kjwl.api.APIManager;
import com.sgb.kjwl.model.entity.ParentAreaEntity;
import com.swgk.core.util.PickSelectEntity;
import com.sgb.kjwl.repository.MachineRepertory;
import com.sgb.kjwl.view.ui.fragment.machine.MapLeaseFragment;
import com.swgk.core.base.BaseViewModel;
import com.swgk.core.base.model.entity.BaseEntity;

import java.util.List;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

public class MapLeaseFragModel extends BaseViewModel {

    private MapLeaseFragment mapLeaseFragment;
    private MachineRepertory repertory;

    public MapLeaseFragModel(MapLeaseFragment mapLeaseF, MachineRepertory repertory){
        this.mapLeaseFragment = mapLeaseF;
        this.repertory = repertory;
    }

    public void getDataList(){

    }

    public void getCityData() {
        APIManager.getInstance().getMachineAPI().getAreaSecondAndThird(repertory.getAreaCode()).enqueue(new Callback<BaseEntity<List<ParentAreaEntity<List<ParentAreaEntity>>>>>() {
            @Override
            public void onResponse(Call<BaseEntity<List<ParentAreaEntity<List<ParentAreaEntity>>>>> call, Response<BaseEntity<List<ParentAreaEntity<List<ParentAreaEntity>>>>> response) {
                if (response.body() == null || response.body().getState() == null) {
                    return;
                }

                if (response.body().getState().equals(APIManager.RESPONSE_OK)) {
                    mapLeaseFragment.showAddressDatas(response.body().getData());
                }
            }

            @Override
            public void onFailure(Call<BaseEntity<List<ParentAreaEntity<List<ParentAreaEntity>>>>> call, Throwable t) {

            }
        });
    }

    public void getClassData() {
        APIManager.getInstance().getPickAPI().getAreaSecond(repertory.getAreaCode()).enqueue(new Callback<BaseEntity<List<PickSelectEntity>>>() {
            @Override
            public void onResponse(Call<BaseEntity<List<PickSelectEntity>>> call, Response<BaseEntity<List<PickSelectEntity>>> response) {
                if (response.body() == null || response.body().getState() == null) {
                    return;
                }

                if (response.body().getState().equals(APIManager.RESPONSE_OK)) {
                    mapLeaseFragment.showClassDatas(response.body().getData());
                }
            }

            @Override
            public void onFailure(Call<BaseEntity<List<PickSelectEntity>>> call, Throwable t) {

            }
        });
    }

    public void getTypeData() {
        APIManager.getInstance().getPickAPI().getAreaSecond(repertory.getAreaCode()).enqueue(new Callback<BaseEntity<List<PickSelectEntity>>>() {
            @Override
            public void onResponse(Call<BaseEntity<List<PickSelectEntity>>> call, Response<BaseEntity<List<PickSelectEntity>>> response) {
                if (response.body() == null || response.body().getState() == null) {
                    return;
                }

                if (response.body().getState().equals(APIManager.RESPONSE_OK)) {
                    mapLeaseFragment.showTypeDatas(response.body().getData());
                }
            }

            @Override
            public void onFailure(Call<BaseEntity<List<PickSelectEntity>>> call, Throwable t) {

            }
        });
    }

    public void getSortData() {
        APIManager.getInstance().getPickAPI().getAreaSecond(repertory.getAreaCode()).enqueue(new Callback<BaseEntity<List<PickSelectEntity>>>() {
            @Override
            public void onResponse(Call<BaseEntity<List<PickSelectEntity>>> call, Response<BaseEntity<List<PickSelectEntity>>> response) {
                if (response.body() == null || response.body().getState() == null) {
                    return;
                }

                if (response.body().getState().equals(APIManager.RESPONSE_OK)) {
                    mapLeaseFragment.showSortDatas(response.body().getData());
                }
            }

            @Override
            public void onFailure(Call<BaseEntity<List<PickSelectEntity>>> call, Throwable t) {

            }
        });
    }
}
